/**
 */
package org.example.RobotModel.robotDsl.impl;

import java.util.Collection;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;

import org.eclipse.emf.common.util.EList;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;

import org.eclipse.emf.ecore.impl.ENotificationImpl;
import org.eclipse.emf.ecore.impl.MinimalEObjectImpl;

import org.eclipse.emf.ecore.util.EObjectContainmentEList;
import org.eclipse.emf.ecore.util.InternalEList;

import org.example.RobotModel.robotDsl.Device;
import org.example.RobotModel.robotDsl.Robot;
import org.example.RobotModel.robotDsl.RobotDslPackage;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>System</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link org.example.RobotModel.robotDsl.impl.SystemImpl#getDevices <em>Devices</em>}</li>
 *   <li>{@link org.example.RobotModel.robotDsl.impl.SystemImpl#getRobot <em>Robot</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class SystemImpl extends MinimalEObjectImpl.Container implements org.example.RobotModel.robotDsl.System
{
  /**
   * The cached value of the '{@link #getDevices() <em>Devices</em>}' containment reference list.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getDevices()
   * @generated
   * @ordered
   */
  protected EList<Device> devices;

  /**
   * The cached value of the '{@link #getRobot() <em>Robot</em>}' containment reference.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getRobot()
   * @generated
   * @ordered
   */
  protected Robot robot;

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  protected SystemImpl()
  {
    super();
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  protected EClass eStaticClass()
  {
    return RobotDslPackage.Literals.SYSTEM;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public EList<Device> getDevices()
  {
    if (devices == null)
    {
      devices = new EObjectContainmentEList<Device>(Device.class, this, RobotDslPackage.SYSTEM__DEVICES);
    }
    return devices;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public Robot getRobot()
  {
    return robot;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public NotificationChain basicSetRobot(Robot newRobot, NotificationChain msgs)
  {
    Robot oldRobot = robot;
    robot = newRobot;
    if (eNotificationRequired())
    {
      ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, RobotDslPackage.SYSTEM__ROBOT, oldRobot, newRobot);
      if (msgs == null) msgs = notification; else msgs.add(notification);
    }
    return msgs;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public void setRobot(Robot newRobot)
  {
    if (newRobot != robot)
    {
      NotificationChain msgs = null;
      if (robot != null)
        msgs = ((InternalEObject)robot).eInverseRemove(this, EOPPOSITE_FEATURE_BASE - RobotDslPackage.SYSTEM__ROBOT, null, msgs);
      if (newRobot != null)
        msgs = ((InternalEObject)newRobot).eInverseAdd(this, EOPPOSITE_FEATURE_BASE - RobotDslPackage.SYSTEM__ROBOT, null, msgs);
      msgs = basicSetRobot(newRobot, msgs);
      if (msgs != null) msgs.dispatch();
    }
    else if (eNotificationRequired())
      eNotify(new ENotificationImpl(this, Notification.SET, RobotDslPackage.SYSTEM__ROBOT, newRobot, newRobot));
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs)
  {
    switch (featureID)
    {
      case RobotDslPackage.SYSTEM__DEVICES:
        return ((InternalEList<?>)getDevices()).basicRemove(otherEnd, msgs);
      case RobotDslPackage.SYSTEM__ROBOT:
        return basicSetRobot(null, msgs);
    }
    return super.eInverseRemove(otherEnd, featureID, msgs);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public Object eGet(int featureID, boolean resolve, boolean coreType)
  {
    switch (featureID)
    {
      case RobotDslPackage.SYSTEM__DEVICES:
        return getDevices();
      case RobotDslPackage.SYSTEM__ROBOT:
        return getRobot();
    }
    return super.eGet(featureID, resolve, coreType);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @SuppressWarnings("unchecked")
  @Override
  public void eSet(int featureID, Object newValue)
  {
    switch (featureID)
    {
      case RobotDslPackage.SYSTEM__DEVICES:
        getDevices().clear();
        getDevices().addAll((Collection<? extends Device>)newValue);
        return;
      case RobotDslPackage.SYSTEM__ROBOT:
        setRobot((Robot)newValue);
        return;
    }
    super.eSet(featureID, newValue);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public void eUnset(int featureID)
  {
    switch (featureID)
    {
      case RobotDslPackage.SYSTEM__DEVICES:
        getDevices().clear();
        return;
      case RobotDslPackage.SYSTEM__ROBOT:
        setRobot((Robot)null);
        return;
    }
    super.eUnset(featureID);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public boolean eIsSet(int featureID)
  {
    switch (featureID)
    {
      case RobotDslPackage.SYSTEM__DEVICES:
        return devices != null && !devices.isEmpty();
      case RobotDslPackage.SYSTEM__ROBOT:
        return robot != null;
    }
    return super.eIsSet(featureID);
  }

} //SystemImpl
